package cn.itguy.mobileguard;

import android.app.ActivityManager;
import android.app.ActivityManager.RunningServiceInfo;
import android.content.Context;

public class CommonUtils {

	/**
	 * Check whether the service specified by the className is running or not.
	 * @param context
	 * @param className
	 * @return 
	 */
	public static boolean isServiceRunning(Context context, String className) {
		ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
		for (RunningServiceInfo rsi : manager
				.getRunningServices(Integer.MAX_VALUE)) {
			if (className.equals(rsi.service.getClassName())) {
				return true;
			}
		}
		return false;
	}

	public static int getDaysBetween(long t1, long t2) {
		long daysInMillis = Math.abs(t1 - t2);
		return (int) (daysInMillis / (1000l * 60 * 60 * 24));
	}

}
